using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerGroundedState : PlayerState
{
    public PlayerGroundedState(PlayerStateMachine _stateMachine, Player _player, string _animBoolName) : base(_stateMachine, _player, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
    }

    public override void Exit()
    {
        base.Exit();
    }

    public override void Update()
    {
        base.Update();

        if(Input.GetKeyDown(KeyCode.R) && player.Skill.Blackhole.blackholeUnlocked)
        {
            if(player.Skill.Blackhole.cooldownTimer > 0)
            {
                player.FX.CreatePopUpText("Cooldown");
                return;
            }

            stateMachine.ChangeState(player.Blackhole);
        }

        if (Input.GetKeyDown(KeyCode.Mouse1) && HasNoSword() && player.Skill.Sword.swordUnlocked)
            stateMachine.ChangeState(player.AimSword);

        if(Input.GetKeyDown(KeyCode.Q) && player.Skill.Parry.parryUnlocked)
            stateMachine.ChangeState(player.CounterAttack);

        if (Input.GetKeyDown(KeyCode.Mouse0))
            stateMachine.ChangeState(player.PrimaryAttack);

        if(!player.isGroundDetected())
            stateMachine.ChangeState(player.AirState);
        
        if(Input.GetKeyDown(KeyCode.W) && player.isGroundDetected())
            stateMachine.ChangeState(player.JumpState);
    }

    private bool HasNoSword()
    {
        if(!player.Sword)
            return true;

        player.Sword.GetComponent<Sword_Skill_Controller>().ReturnSword();
        return false;
    }
}
